id: don't exit 1 when uid/gid name lookup fails in default output#12341
Open
c-tonneslan wants to merge 1 commit into
Open
id: don't exit 1 when uid/gid name lookup fails in default output#12341c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
When running in a container (or anywhere /etc/passwd doesn't have an
entry for the current uid/gid), uutils id was printing the numeric
fallback and exiting 1:
$ id
id: cannot find name for group ID 1234
id: cannot find name for group ID 1234
uid=0(root) gid=1234(1234) groups=1234(1234)
$ echo $?
1
That breaks docker startup scripts that probe with `id`. GNU id
prints the numeric value and exits 0 in that case.
The set_exit_code(1) calls in the default printer are wrong: failing
to name-resolve a uid isn't an error in the no-flag invocation, only
when the user explicitly asked for a name with -n. The five lookup
sites in the default formatter now just fall back to the numeric
string and keep the exit code at 0.
The -n/--name paths still set exit 1 on lookup failure (that's the
documented GNU behavior).
Closes uutils#12246.
Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Contributor
|
already opened #12252 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12246.
In a docker container where the current gid doesn't have an entry in
/etc/passwd//etc/group, uutils id was printing the fallback numeric value but then exiting 1:That breaks init scripts that probe identities with plain
id. GNU id prints the numeric value and exits 0.The bug was a
set_exit_code(1)call in each of the five lookup sites in the default formatter (uid, gid, euid, egid, groups). Failing to resolve a name isn't an error in the no-flag case, only with-n/--namewhere the user explicitly asked for a name. The-npaths still set exit 1, matching GNU.I left the
id: cannot find name...warning in place since it's informational; happy to also drop that if you'd prefer the cleaner GNU output.